package com.zhou.juc.test02_synchronized;

import java.util.concurrent.TimeUnit;

/**
 * 一个同步方法可以调用另外一个同步方法，一个线程已经拥有某个对象的锁，再次申请的时候仍然会得到该对象的锁.
 * 也就是说synchronized获得的锁是可重入的
 * @author zhouyanxiang
 * @create 2020-06-2020/6/20-10:17
 */
public class T5  {
    public synchronized void m1(){
        try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        m2();
        System.out.println(" --- m1 --- ");
    }

    public synchronized void m2(){
        try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(" --- m2 --- ");
    }

    public static void main(String[] args) {
        new T5().m1();
    }
}
